package org.csu.mypetstore.web.Filter;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.tools.WebLog;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class LogoutFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        Account account = (Account) ((HttpServletRequest)servletRequest).getSession().getAttribute("account");
        if(account!=null) {
            WebLog.WriteWebLog(account.getUsername()+" logged out ");
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
